#ifndef _RW_LOCK_H_
#define _RW_LOCK_H_

/*
 * A process-shared Read-Write lock that is based on semaphores.
 */

#include <semaphore.h>

typedef struct rwlock
{
	sem_t *readsem;
	sem_t *writesem;
} rwlock_t;



/* Opens and (optionally) creates a new RW-lock */
rwlock_t* rwlock_create(const char *name);

/* Closes the current RW-lock */
void rwlock_close(rwlock_t *lock);

/* Removes the RW-lock that is corresponding to the given name */
void rwlock_destroy(const char *name);




/* Acquire a Read-Lock */
void rwlock_read_lock(rwlock_t *lock);

/* Release a Read-Lock */
void rwlock_read_unlock(rwlock_t *lock);


/* Acquire a Write-Lock */
void rwlock_write_lock(rwlock_t *lock);

/* Release a Write-Lock */
void rwlock_write_unlock(rwlock_t *lock);



#endif /* _RW_LOCK_H_ */

